feat: add auth preprocessor and update auth handler.#227
feat: add auth preprocessor and update auth handler.#227kalenkevich wants to merge 4 commits intomainfrom
Conversation
2aec29d to
14b0376
Compare
c2292e3 to
917ee86
Compare
679c86e to
60c4aa6
Compare
60c4aa6 to
2eabe19
Compare
ScottMansfield
left a comment
There was a problem hiding this comment.
I'm only partway through review but I thought it's best to leave what I have for now
| access_token?: string; | ||
| refresh_token?: string; | ||
| expires_in?: number; | ||
| id_token?: string; |
There was a problem hiding this comment.
nit: ordering. Put this one line up
| if (this.authConfig.exchangedAuthCredential) { | ||
| state.set(credentialKey, this.authConfig.exchangedAuthCredential); | ||
| } | ||
|
|
||
| const authSchemeType = this.authConfig.authScheme.type; | ||
| if (!['oauth2', 'openIdConnect'].includes(authSchemeType)) { | ||
| return; | ||
| } |
There was a problem hiding this comment.
Do we want to store the auth in the state even if it's not a supported auth scheme?
|
|
||
| const authSchemeType = this.authConfig.authScheme.type; | ||
| if (!['oauth2', 'openIdConnect'].includes(authSchemeType)) { | ||
| return; |
There was a problem hiding this comment.
Is this not an error if the scheme is invalid?
| authCredential: this.authConfig.exchangedAuthCredential, | ||
| authScheme: this.authConfig.authScheme, | ||
| }); | ||
| state.set(credentialKey, exchangedCredential.credential); |
There was a problem hiding this comment.
This is set twice and the check for the exchangedAuthCredential is done twice here. I think understanding this depends on the above comments I made.
| if ('authorizationUrl' in flow && flow.authorizationUrl) { | ||
| authorizationEndpoint = flow.authorizationUrl; | ||
| } else if ('tokenUrl' in flow && flow.tokenUrl) { | ||
| authorizationEndpoint = flow.tokenUrl; | ||
| } |
There was a problem hiding this comment.
For the authorizationCode flow, there's both authorizationUrl and tokenUrl defined, does authorizationUrl override tokenUrl?
Overview
This PR improves the test coverage and fixes inconsistencies in the authentication handling logic for the ADK-JS project. It addresses a bug in
AuthHandlerwhere exchange results were stored incorrectly, enhances existing tests to verify actual generated values (like URLs and states), and introduces a new unit test suite for theAuthPreprocessor.Key Changes
Bug Fixes
AuthHandler
parseAndStoreAuthResponsewhere the fullExchangeResultobject was unintentionally stored in session state. Now, it correctly stores only the nestedAuthCredential(exchangedCredential.credential), aligning with howgetAuthResponseretrieves it.Testing Enhancements
AuthHandler Tests
parseAndStoreAuthResponseto cover:generateAuthUritests now assert the actual generated URL string and query parameters (such asclient_id,redirect_uri,scope, and dynamicstate) rather than returning stubs.generateAuthRequesttests assert usage of the generated credentials.[NEW] AuthPreprocessor Tests
AuthPreprocessor.runAsyncgenerator logic:LlmAgent.adk_request_credentialtool-resume responses.handleFunctionCallsAsync.handleFunctionCallsAsync.